package com.menhai.personmanagement.utils;

import cn.hutool.poi.excel.ExcelWriter;
import com.menhai.personmanagement.entity.Codelist;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationConstraint;
import org.apache.poi.ss.usermodel.DataValidationHelper;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddressList;

import java.util.List;
import java.util.stream.Collectors;

public class ExcelOperUtil {



    public static DataValidation addSelect(ExcelWriter writer, String[] data, int firstRow, int firstCol){
        Sheet sheet = writer.getSheet();
        CellRangeAddressList addressList1 = new CellRangeAddressList(firstRow, 5000,firstCol,firstCol);
        DataValidationHelper dataValidationHelper1 = sheet.getDataValidationHelper();
        DataValidationConstraint constraint1 = dataValidationHelper1.createExplicitListConstraint(data);
        DataValidation dataValidation1 = dataValidationHelper1.createValidation(constraint1, addressList1);
        return dataValidation1;
    }

    public static String[] codesString (List<Codelist> codelists){

        //list
        List<String> stringList =codelists.stream().map(Codelist::getCodeName).collect(Collectors.toList());

        return stringList.toArray(new String[stringList.size()]);
    }
}
